package com.xjh.him.controller;

import com.xjh.him.annotation.LoginVerify;
import com.xjh.him.dto.friendgroupmsg.FriendGroupMsgDTO;
import com.xjh.him.dto.friendgroupmsg.FriendGroupMsgQueryDTO;
import com.xjh.him.service.FriendGroupMsgServiceImpl;
import com.xjh.him.vo.friendgroupmsg.FriendGroupMsgQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.xjh.tool.Checks;
import org.xjh.tool.common.ErrorMsg;
import org.xjh.tool.dto.ResultDTO;
import org.xjh.tool.vo.AjaxResultVO;

import java.util.List;

@RestController
@RequestMapping("/friend/group/msg")
public class FriendGroupMsgController {

    @Autowired
    private FriendGroupMsgServiceImpl friendGroupMsgService;


    @LoginVerify
    @RequestMapping("/history")
    public AjaxResultVO queryHistoryMsg(@RequestBody FriendGroupMsgQueryVO queryVO) {
        if (Checks.isAnyEmpty(queryVO, queryVO.getGroupId())) {
            return AjaxResultVO.getFailureResult(ErrorMsg.ERR_PARAMETER_IS_NULL);
        }
        FriendGroupMsgQueryDTO queryDTO = new FriendGroupMsgQueryDTO();
        queryDTO.setGroupId(queryVO.getGroupId());
        queryDTO.setLimit(queryVO.getPerPageSize());
        queryDTO.setSkip((queryVO.getPage() - 1) * queryVO.getPerPageSize());
        ResultDTO<List<FriendGroupMsgDTO>> resultDTO = friendGroupMsgService.queryHistoryMsg(queryDTO);
        if (resultDTO.isSuccess()) {
            return AjaxResultVO.getSuccessResult(resultDTO.getResult());
        }
        return AjaxResultVO.getFailureResult(resultDTO.getErrMsg());
    }
}
